package com.blb.controller;


import com.blb.entity.CargoSpace;
import com.blb.service.ICargoSpaceService;
import com.blb.utils.*;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *货位管理
 * @author wss
 * @since 2020-05-27
 */
@RestController
@RequestMapping("/cargoSpace")
public class CargoSpaceController {
    @Autowired
    private ICargoSpaceService cargoSpaceService;

    /**
     * 分页查询货位
     * @param sId
     * @param csNo
     * @param csStatus
     * @param shelfNo
     * @param draw
     * @param start
     * @param length
     * @return
     */
    @RequiresPermissions("storywei")
    @RequestMapping("cargoID_manage")
    public DataTablesPage<CargoSpace> cargoID_manage(String sId, String csNo,String csStatus,String shelfNo, Integer draw, Integer start, Integer length) {
        String companyId = ShiroUtils.getCompany();
        Map<String, Object> map = new HashMap<>();
        map.put("companyId", companyId);
        map.put("sId",sId);
        map.put("csNo",csNo);
        map.put("csStatus",csStatus);
        map.put("shelfNo",shelfNo);
        int pageCount = cargoSpaceService.getPageCount(map);
        map.put("start",start);
        map.put("length",length);
        List<CargoSpace> pageList = cargoSpaceService.getCargoSpaceByShelf(map);

        return new DataTablesPage<>(draw,pageCount,pageCount,pageList) ;
    }

    /**
     * 添加货位
     * @param entity
     * @return
     */
    @RequiresPermissions("storywei:add")
    @RequestMapping("add")
    public Response add(CargoSpace entity){
        entity.setId(UUIDUtils.getId());
        entity.setCompanyId(ShiroUtils.getCompany());
        entity.setCreateTime(TimeUtils.getNowTime());
        cargoSpaceService.save(entity);
        return Response.success("添加成功");
    }

    /**
     * 修改货位信息
     * @param entity
     * @return
     */
    @RequiresPermissions("storywei:update")
    @RequestMapping("update")
    public Response update(CargoSpace entity){
        cargoSpaceService.updateById(entity);
        return Response.success("修改成功");
    }

    /**
     * 修改货位状态
     * @param entity
     * @return
     */
    @RequiresPermissions("storywei:update")
    @RequestMapping("updateStatus")
    public Response updateStatus(CargoSpace entity){
        CargoSpace pojo = cargoSpaceService.getById(entity.getId());
        pojo.setCargoSpaceStatus(entity.getCargoSpaceStatus());
        cargoSpaceService.updateById(pojo);
        return Response.success("修改成功");
    }



}

